package com.bigknow.appstore.web.framework.entity;

import com.bigknow.appstore.common.util.StringUtils;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.Transient;

/**
 * Created by TwelveFoldEr on 2016/3/15.
 */
public abstract class BaseEntity implements IEntity {
    @Id
    private String id;

    @Transient
    private String orderByName;
    @Transient
    private String orderBy;
    // For fuzzy search
    @Transient
    private String fuzzyField;

    public String getOrderByName() {
        return orderByName;
    }

    public void setOrderByName(String orderByName) {
        this.orderByName = orderByName;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    /**
     * 获取模糊查找字段信息，如果为null，后续就不执行模糊查找
     *
     * @return
     */
    public String getFuzzyField() {
        return fuzzyField;
    }

    /**
     * 设置模糊查找字段，如果设置为null
     *
     * @param fuzzyField
     */
    public void setFuzzyField(String fuzzyField) {
        this.fuzzyField = fuzzyField;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String trim(String value) {
        if (StringUtils.isNotBlank(value)) {
            return value.trim();
        } else {
            return value;
        }
    }
}
